// pages/myFollow/myFollow.js
import config from './../../utils/consts.js'
import util from './../../utils/util.js'

const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    startX: 0, //开始坐标
    startY: 0,
    isAdminLogin: false, //管理员是否登录
    adminInfo: {}, //管理员登录信息
    info: {},
    params: {
      page: 1,
      numPerPage: 2
    },
    memberParams: { //管理员bar成员分页条数
      page: 1,
      numPerPage: 10
    },
    // newsParams: {//管理员新闻分页条数
    //   page: 1,
    //   numPerPage: 10
    // },
    // activityParams: {
    //   page: 1,
    //   numPerPage: 10
    // },
    // noticeParams: {
    //   page: 1,
    //   numPerPage: 10
    // },
    memberlist: [], //管理员成员列表
    newslist: [], //管理员新闻列表
    activitylist: [], //管理员活动列表
    noticelist: [], //管理员普通用户公用消息列表
    memberCount: 0,
    newsCount: 0,
    activityCount: 0,
    noticeCount: 0,
    actTab: 'association', //普通用户当前bar文本标志
    adminActTab: 'adminMemberTab', //管理员当前bar文本标志
    isShowRemove: false,
    // refuseShow:false
    // isOperation: '',  //1是同意 2是拒绝
    url: app.data.imgUrl, //图片路径
    userInfo: null,
    assParams: { //普通用户的社团分页条数
      page: 1,
      numPerPage: 5
    },
    noticeParams: { //普通用户和管理员的消息分页条数
      page: 1,
      numPerPage: 5
    },
    activeParams: { //普通用户的活动分页条数
      page: 1,
      numPerPage: 5
    },
    assList: [], //普通用户社团列表
    activeList: [], //获取普通用户活动列表
    adminLoginParams: { //管理员登录是的账户信息暂存
      username: '',
      password: ''
    },
    showDialog: false,
    currentNotice: {
      data: null,
      index: 0
    },
    /*refuseReson: '',*/
    removeMember: null, // 需要移除的成员
    navTab: [{
      name: '社团',
      value: 'association'
    }, {
      name: '活动',
      value: 'activity'
    }, {
      name: '消息',
      value: 'notice'
    }],
    adminNavTab: [{
      name: '成员',
      value: 'adminMemberTab',
      countName: 'memberCount'
    }, {
      name: '新闻',
      value: 'adminNewsTab',
      countName: 'newsCount'
    }, {
      name: '活动',
      value: 'adminActivityTab',
      countName: 'activityCount'
    }, {
      name: '消息',
      value: 'adminNoticeTab',
      countName: 'noticeCount'
    }],
    refusebody: { //拒绝事件参数
      applyId: 0,
      result: -1,
      reason: ''
    },
    refuseMask: true, //拒绝Box状态是否显示
    textareaValue: "" //拒绝弹出框内容 清空
  },
  //获取用户信息
  getUserDetail(id) {
    wx.teamApi.account.info(id).then(res => {
      this.setData({
        userInfo: res.data.result
      })
      app.globalData.userInfoDetail = res.data.result
    })
  },
  //
  accLoadmore() {
    this.data.assParams.page += 1
    this.getAssociation(this.data.assParams) //获取普通用户社团列表
  },
  activeLoadmore() {
    this.data.activeParams.page += 1
    this.getActive(this.data.activeParams) //获取普通用户活动列表
  },
  msgLoadmore() {
    this.data.noticeParams.page += 1
    this.getNotice(this.data.noticeParams) //获取普通用户消息列表
  },
  //同意事件
  agree(e) {
    let data = e.currentTarget.dataset.data
    let index = e.currentTarget.dataset.index
    let body = {
      applyId: data.id,
      result: 1,
      reason: ''
    }
    wx.teamApi.association.adminExamin(body).then(res => {
      if (res.data.errcode === 0) {
        this.data.noticelist[index].applyRecord.applyResult = 1
        this.setData({
          noticelist: this.data.noticelist
        })
        this.adminInfo() //重新查询列表条数
      } else {
        wx.showToast({
          title: '操作失败！',
        })
      }
    })


  },
  //tabBar点击切换事件
  tabBar(e) {
    var tabtype = e.currentTarget.dataset.type;
    if (this.data.isAdminLogin) { //判断管理员登录
      // if (tabtype === 'adminNoticeTab') {
      //   // this.data.noticeParams.page = 1
      //   // this.getNotice(this.data.noticeParams, true)
      //   console.log(tabtype)
      //   console.log('166')
      // }
      this.setData({
        adminActTab: tabtype
      })
    } else { //非管理员
      console.log('175')
      if (tabtype === 'notice') { //获取普通用户消息列表
        this.data.noticeParams.page = 1
        this.getNotice(this.data.noticeParams, true)
      } else if (tabtype === 'activity') {
        console.log(tabtype)
      } else if (tabtype === 'association') {
        console.log(tabtype)
      }
      this.setData({
        actTab: tabtype
      })
    }

  },
  //通用跳转页面
  goto(e) {
    let url = e.currentTarget.dataset.url
    console.log(url)
         wx.navigateTo({
        url: url,
      }) 
  },

  //活动新闻审核状态来跳转
  gotoNewandActivity(e) {
    let url = e.currentTarget.dataset.url
    // console.log('191')
    console.log(e)
    if (e.currentTarget.dataset.item.approvalStatus == 0) {
      wx.showToast({
        title: '审核中,无法操作！',
        icon: 'none'
      })
    }
    else if (e.currentTarget.dataset.item.approvalStatus == 3) {
      wx.showToast({
        title: '审核不通过,无法操作！',
        icon: 'none'
      })
    } else {
      wx.navigateTo({
        url: url,
      })
    }

  },

  //动态获取账号输入信息
  usernameInput(e) {
    this.setData({
      'adminLoginParams.username': e.detail.value
    })
  },
  //动态获取密码输入信息
  pwdInput(e) {
    this.setData({
      'adminLoginParams.password': e.detail.value
    })
  },
  //管理员登录事件
  adminLogin() {
    if (this.data.adminLoginParams.username.length > 0 && this.data.adminLoginParams.password.length > 0) {
      wx.teamApi.login.adminlogin(this.data.adminLoginParams).then(res => {
        if (res.data.errcode === 0) {
          this.hideLogin() //隐藏登录框
          let data = res.data.result
          this.getAdminDetail(data.associationId) //根据管理员id获取详细信息
          util.setAdminToken(data.token)
          wx.setStorageSync('adminUserInfo', data)
          wx.setStorageSync('teamLogin', true)
          this.setData({
            isAdminLogin: true,
            isShowLogin: false,
            'adminLoginParams.username': '',
            'adminLoginParams.password': ''
          })
          this.adminInfo() //获取管理员各个bar的信息条数
          this.refresh()
          
        }
      })
    }
  },

  //获取普通用户社团列表
  getAssociation(page, bool) {
    wx.teamApi.account.myassociation(page).then(res => {
      if (bool) {
        this.setData({
          assList: res.data.result
        })
      } else {
        if (res.data.result.length <= 0) {
          this.data.assParams.page -= 1
        }
        this.setData({
          assList: this.data.assList.concat(res.data.result)
        })
      }
      console.log('272')
      console.log(res.data.result)
    })
  },

  //获取普通用户消息列表
  getNotice(page, bool) {
    wx.teamApi.account.mynotice(page).then(res => {
      if (bool) {
        this.setData({
          noticeList: res.data.result
        })
      } else {
        if (res.data.result.length <= 0) {
          this.data.noticeParams.page -= 1
        }
        this.setData({
          noticeList: this.data.noticeList.concat(res.data.result)
        })
      }
    })

  },
  //获取普通用户活动列表
  getActive(page, bool) {
    wx.teamApi.account.myactivity(page).then(res => {
      if (bool) {
        this.setData({
          activeList: res.data.result
        })
      } else {
        if (res.data.result.length <= 0) {
          this.data.activeParams.page -= 1
        }
        this.setData({
          activeList: this.data.activeList.concat(res.data.result)
        })
      }
    })
  },
  //admin
  go(e) { //跳转页面
    var url = e.currentTarget.dataset.url
    wx.navigateTo({
      url: url
    })
  },
  //管理员切换tab
  admintabBar(e) {
    var type = e.currentTarget.dataset.type;
    var params = this.data.params
    params.page = 1
    this.setData({
      adminActTab: type,
      params: params
    })
    if (type === "adminMemberTab") { ////管理员获取成员列表
      this.adminMemberlist(this.data.params, false)
    } else if (type === "adminNewsTab") { ////管理员获取新闻列表
      this.adminNewslist(this.data.params, false)
    } else if (type === "adminActivityTab") { //管理员获取活动列表
      this.adminActivitylist(this.data.params, false)
    } else {
      //获取管理员消息
      this.adminNoticelist(this.data.params, false)
    }
  },
  // 删除新闻
  removeNews(e) {
    let data = e.currentTarget.dataset.item
    let index = e.currentTarget.dataset.index
    let type = e.currentTarget.dataset.type
    wx.showModal({
      title: "警告",
      content: '删除后不可撤销，确定？',
      success: (res) => {
        if (res.confirm) {
          wx.teamApi.association.adminDeleteNews(data.id).then(apires => {
            if (apires.data.errcode === 0) {
              wx.showToast({
                title: '删除成功',
              })
              if (type ==0) {
                this.data.newslist.splice(index, 1)
                this.setData({
                  'info.newsCount': --this.data.info.newsCount,
                  newslist: this.data.newslist
                })
              } else {
                this.data.activitylist.splice(index, 1)
                this.setData({
                  'info.activityCount': --this.data.info.activityCount,
                  activitylist: this.data.activitylist
                })
              }
            } else {
              wx.showToast({
                icon: 'none',
                title: apires.data.err,
              })
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  //移除成员事件
  remove(e) {
    wx.showModal({
      title: '提示',
      content: '确定移除改成员吗？',
      success: (act) => {
        if (act.confirm) {
          wx.teamApi.association.adminDeletemember(e.currentTarget.dataset.item.id).then(res => {
            if (res.data.errcode === 0) {
              wx.showToast({
                title: '移除成功'
              })
              this.closeRemoveMember()
              this.data.memberlist.splice(e.currentTarget.dataset.index, 1)
              this.adminInfo()
              this.setData({
                memberlist: this.data.memberlist
              })
            } else {
              wx.showModal({
                title: '提示',
                content: '移除失败，请稍后重试'
              })
            }
          })
        }
      }
    })
  },
  closeRemoveMember() {
    this.setData({
      isShowRemove: false
    })
  },
  // closeRefuse() { //关闭拒绝窗口
  //   this.setData({
  //     refuseShow: false
  //   })
  // },

  //拒绝事件
  refuseShow(e) {
    //功能将标题栏状态栏样式改变
    wx.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#7f4f00',
    })
    let data = e.currentTarget.dataset.data
    let index = e.currentTarget.dataset.index
    this.setData({
      refuseShow: true,
      refuseMask: false,
      'refusebody.applyId': data.id,
    })
    this.data.currentNotice.data = data
    this.data.currentNotice.index = index
    //console.log(body)

  },
  //提交拒绝理由事件
  fromsubmit(e) {
    this.data.refusebody.reason = e.detail.value.refuseText
    if (this.data.refusebody.reason.length === "" || this.data.refusebody.reason.length === 0) {
      wx.showToast({
        title: '请输入拒绝理由',
        icon: 'none'
      })
    } else {
      this.refuse() //拒绝事件
    }
  },
  //关闭拒绝理由输入框
  bindClose() {
    wx.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#ff9f00',
    })
    this.setData({
      refuseMask: true,
      textareaValue: ""
    })
  },
  // setRefuseReson(e) {
  //   this.data.refuseReson = e.detail.value
  // },

  //拒绝事件
  refuse() {
    let body = this.data.refusebody
    console.log('467')
    console.log(body)
    wx.teamApi.association.adminExamin(body).then(res => {
      if (res.data.errcode === 0) {
        this.data.noticelist[this.data.currentNotice.index].applyRecord.applyResult = -1
        this.adminInfo() //重新查询列表条数
        this.setData({
          noticelist: this.data.noticelist,
          refuseMask: true,
          'refusebody.applyId': 0,
          'refusebody.reason': ""
        })
      } else {
        wx.showToast({
          title: '操作失败！',
        })
      }
    })
  },
  // 取人数，活动数，新闻、消息数量
  adminInfo() {
    wx.teamApi.association.adminInfo().then(res => {
      this.setData({
        info: res.data.result
      })
      console.log('499')
      console.log(res.data.result)
    })
  },
  //管理员获取成员列表
  adminMemberlist(params, tag) {
    wx.teamApi.association.adminMemberlist(params).then(res => {
      console.log('499')
      console.log(res)
      var len = res.data.result.length
      if (len >= 10) {
        this.setData({
          memberCount: 0
        })
      } else {
        this.setData({
          memberCount: 1
        })
      }
      if (tag) {
        this.setData({
          memberlist: this.data.memberlist.concat(res.data.result)
        })
      } else {
        this.setData({
          memberlist: res.data.result
        })
      }
    })
  },
  //管理员获取新闻列表
  adminNewslist(params, tag) {
    wx.teamApi.association.adminNewslist(params).then(res => {
      var len = res.data.result.length
      console.log('528')
      console.log(res)
      if (len >= 10) {
        this.setData({
          newsCount: 0
        })
      } else {
        this.setData({
          newsCount: 1
        })
      }
      if (tag) {
        this.setData({
          newslist: this.data.newslist.concat(res.data.result)
        })
      } else {
        this.setData({
          newslist: res.data.result
        })
      }
    })
  },
  ////管理员获取活动列表
  adminActivitylist(params, tag) {
    wx.teamApi.association.adminActivitylist(params).then(res => {
      var len = res.data.result.length
      if (len >= 10) {
        this.setData({
          activityCount: 0
        })
      } else {
        this.setData({
          activityCount: 1
        })
      }
      if (tag) {
        this.setData({
          activitylist: this.data.activitylist.concat(res.data.result)
        })
      } else {
        this.setData({
          activitylist: res.data.result
        })
      }
      console.log(540)
      console.log(res)
    })
  },
  //获取管理员消息列表
  adminNoticelist(params, tag) {
    wx.teamApi.association.adminNoticelist(params).then(res => {
      var len = res.data.result.length
      if (len >= 10) {
        this.data.noticeCount = 0
      } else {
        this.data.noticeCount = 1
      }
      if (tag) {
        this.setData({
          noticelist: this.data.noticelist.concat(res.data.result)
        })
      } else {
        this.setData({
          noticelist: res.data.result
        })
      }
    })
  },
  //退出登录
  exitAdmin() {
    console.log(552)
    wx.showModal({
      title: '提示',
      content: '是否退出社团账号？',
      success: (act) => {
        if (act.confirm) { //退出登录成功过后查询普通用户信息
          wx.teamApi.login.adminlogout().then(res => {
            wx.clearStorageSync()
            util.setToken(res.data.result.token)
            wx.setStorageSync('loginInfo', res.data.result)
            this.setData({
              isAdminLogin: false
            })
            // this.data.assParams.page = 1
            // this.data.noticeParams.page = 1
            // this.data.activeParams.page = 1
            // this.getAssociation(this.data.assParams, true) //获取普通用户社团列表
            // this.getNotice(this.data.noticeParams, true) //获取普通用户消息列表
            // this.getActive(this.data.activeParams, true) //获取普通用户活动列表
            //当管理员切换账户时同时跟新一般用户
            let userId = wx.getStorageSync('loginInfo').accId
            this.getUserDetail(userId)
            this.refresh()
            // wx.redirectTo({
            //   url: '../my/my',
            // })
          })
        }
      }
    })

  },
  adminAccLoadmore: function() {
    var actTab = this.data.adminActTab
    var params = this.data.params
    var memberCount = this.data.memberCount,
      newsCount = this.data.newsCount,
      activityCount = this.data.activityCount,
      noticeCount = this.data.noticeCount;
    if (actTab === 'adminMemberTab') { //成员
      if (memberCount === 0) {
        params.page++
          this.setData({
            params: params
          })
        //管理员获取成员列表
        this.adminMemberlist(this.data.params, true)
      }
    } else if (actTab === 'adminNewsTab') { //新闻
      if (newsCount === 0) {
        params.page++
          this.setData({
            params: params
          })
        //管理员获取新闻列表
        this.adminNewslist(this.data.params, true)
      }
    } else if (actTab === 'adminActivityTab') { //活动
      if (activityCount === 0) {
        params.page++
          this.setData({
            params: params
          })
        //管理员获取活动列表
        this.adminActivitylist(this.data.params, true)
      }
    } else { //消息
      if (noticeCount === 0) {
        params.page++
          this.setData({
            params: params
          })
        //获取管理员消息
        this.adminNoticelist(this.data.params, true)
      }
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {},
  msgTap(e) {
    let item = e.currentTarget.dataset.item
    wx.teamApi.account.read(item.newsId) // 设置消息为已读
    if (item.type === config.messageType.comment) {
      wx.navigateTo({
        url: `../newsAndActivityDetails/newsAndActivityDetails?id=${item.newsId}&floorNum=${item.extra}&commentId=${item.eventId}`,
      })
    }
  },
  accClick(e) {
    let item = e.currentTarget.dataset.item
    wx.navigateTo({
      url: `../associationDetails/associationDetails?id=${item.id}`
    })
  },
  //登录事件
  gotoLogin() {
    wx.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#7f4f00',
    })
    this.setData({
      isShowLogin: true
    })
  },
  hideLogin() {
    wx.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#ff9f00',
    })
    this.setData({
      isShowLogin: false
    })
  },
  //根据管理员id获取详细信息
  getAdminDetail(id) {
    wx.teamApi.association.detail(id).then(res => {
      let tempName=''
      if (res.data.result.name.length>10){
        tempName = res.data.result.name.substring(0,9)+'...'
        res.data.result.name=tempName
      }
      this.setData({
        adminInfo: res.data.result
      })

      console.log('762')
      console.log(tempName)
      console.log(this.data.adminInfo)
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    //页面显示的时候执行样式
    this.setData({
      isAdminLogin: !!wx.getStorageSync('teamLogin'), //判断是否管理员用户登录
      userInfo: app.globalData.userInfo,
      textareaValue: "", //清空拒绝输入框  
      'adminLoginParams.username': '', //清空管理员登录信息
      'adminLoginParams.password': ''
    })
    //回复状态栏默认样式
    wx.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#ff9f00',
    })
    if (!this.data.isAdminLogin) { //非管理员登录
      let userId = wx.getStorageSync('loginInfo').accId
      this.getUserDetail(userId)
      this.data.assParams.page = 1
      this.data.noticeParams.page = 1
      this.data.activeParams.page = 1
    } else {
      //1、先获取最新的给个bar数目
      this.adminInfo()
      // //管理员获取成员列表
      // this.adminMemberlist(this.data.memberParams, false)
      let admininfo = wx.getStorageSync('adminUserInfo')
      //获取管理员信息
      this.getAdminDetail(admininfo.associationId)
      //例如当管理员点击了消息bar时，切换到底部其他tabbar时，再回到这里时刷新当前页面
      //this.refresh()
    }
    //2、更新对应的bar信息
    this.refresh()
    console.log('754')
    console.log(this.data.noticelist)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {
    this.setData({
      isShowLogin: false, //控制管理员登录框显示
      refuseMask: true //控制拒绝遮罩显示
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },
  //通用重新拉去各个tabbar信息
  refresh() {
    if (this.data.isAdminLogin) {
      var adminActTab = this.data.adminActTab
      if (adminActTab === 'adminMemberTab') { //成员
        var params = this.data.params
        params.page = 1
        this.setData({
          params: params
        })
        //管理员获取成员列表
        this.adminMemberlist(this.data.params, false)
      } else if (adminActTab === 'adminNewsTab') { //新闻
        var params = this.data.params
        params.page = 1
        this.setData({
          params: params
        })
        //管理员获取新闻列表
        this.adminNewslist(this.data.params, false)
      } else if (adminActTab === 'adminActivityTab') { //活动
        var params = this.data.params
        params.page = 1
        this.setData({
          params: params
        })
        //管理员获取活动列表
        this.adminActivitylist(this.data.params, false)
      } else { //消息
        var params = this.data.params
        params.page = 1
        this.setData({
          params: params
        })
        //获取管理员消息
        this.adminNoticelist(this.data.params, false)
      }
    } else {
      switch (this.data.actTab) {
        case 'association':
          this.data.assParams.page = 1
          this.getAssociation(this.data.assParams, true) //获取普通用户社团列表
          break
        case 'activity':
          this.data.activeParams.page = 1
          this.getActive(this.data.activeParams, true) //获取普通用户活动列表
          break
        case 'notice':
          this.data.noticeParams.page = 1
          this.getNotice(this.data.noticeParams, true) //获取普通用户消息列表
          break
        default:
          break
      }
    }
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    this.refresh()
    wx.stopPullDownRefresh()
    console.log('846')
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    if (this.data.isAdminLogin) {
      this.adminAccLoadmore()
      // switch (this.data.actTab) {
      //   case 'adminMemberTab':
      //     this.adminAccLoadmore()
      //     break
      //   case 'adminNewsTab':
      //     this.adminAccLoadmore()
      //     break
      //   case 'adminActivityTab':
      //     this.adminAccLoadmore()
      //     break
      //   case 'adminNoticeTab':
      //     break
      //   default:
      //     break
      // }
    } else {
      switch (this.data.actTab) {
        case 'association':
          this.accLoadmore()
          break
        case 'activity':
          this.activeLoadmore()
          break
        case 'notice':
          this.msgLoadmore()
          break
        default:
          break
      }
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '我新发现了一个有趣社团，我在这里等你哟',
      imgUrl: 'https://aa-1257564155.cos.ap-chengdu.myqcloud.com/tmp_955d50b786dc9776a422b990a07f26cc.jpg',
      path: '/pages/login/login?id=123'
    }
  },
  //手指触摸动作开始 记录起点X坐标
  touchstart: function(e) {
    //开始触摸时 重置所有删除
    this.data.memberlist.forEach(function(v, i) {
      if (v.isTouchMove) //只操作为true的
        v.isTouchMove = false;
    })
    this.setData({
      startX: e.changedTouches[0].clientX,
      startY: e.changedTouches[0].clientY,
      memberlist: this.data.memberlist
    })
  },
  //滑动事件处理
  touchmove: function(e) {
    var that = this,
      index = e.currentTarget.dataset.index, //当前索引
      startX = that.data.startX, //开始X坐标
      startY = that.data.startY, //开始Y坐标
      touchMoveX = e.changedTouches[0].clientX, //滑动变化坐标
      touchMoveY = e.changedTouches[0].clientY, //滑动变化坐标
      //获取滑动角度
      angle = that.angle({
        X: startX,
        Y: startY
      }, {
        X: touchMoveX,
        Y: touchMoveY
      });
    that.data.memberlist.forEach(function(v, i) {
      v.isTouchMove = false
      //滑动超过30度角 return
      if (Math.abs(angle) > 30) return;
      if (i == index) {
        if (touchMoveX > startX) //右滑
          v.isTouchMove = false
        else //左滑
          v.isTouchMove = true
      }
    })
    //更新数据
    that.setData({
      memberlist: that.data.memberlist
    })
  },
  /**
   * 计算滑动角度
   * @param {Object} start 起点坐标
   * @param {Object} end 终点坐标
   */
  angle: function(start, end) {
    var _X = end.X - start.X,
      _Y = end.Y - start.Y
    //返回角度 /Math.atan()返回数字的反正切值
    return 360 * Math.atan(_Y / _X) / (2 * Math.PI);
  },
  //删除事件
  del: function(e) {
    this.data.memberlist.splice(e.currentTarget.dataset.index, 1)
    this.setData({
      memberlist: this.data.memberlist
    })
  },

  zanClick(e) {
    let item = e.currentTarget.dataset.item
    let index = e.currentTarget.dataset.index
    if (e.currentTarget.dataset.item.approvalStatus == 0) {//0 审核中 1审核通过 2默认 3不通过
      wx.showToast({
        title: '审核中,无法操作！',
        icon: 'none'
      })
    } else if (e.currentTarget.dataset.item.approvalStatus == 3) {
      wx.showToast({
        title: '审核不通过,无法操作！',
        icon: 'none'
      })
    } else {
      if (item.upStatus) {
        this.cancelUpNews(item.id, index)
      } else {
        this.upNews(item.id, index)
      }
    }

  },
  //取消赞
  cancelUpNews(id, index) {
    wx.teamApi.news.cancelUpNews(id).then(res => {
      if (res.data.errcode === 0) {
        if (this.data.adminActTab === 'adminNewsTab') {
          this.data.newslist[index].upStatus = 0
          this.data.newslist[index].upNum -= 1
          //console.log(this.data.infoList[index])
          this.setData({
            newslist: this.data.newslist
          })
        } else {
          this.data.activitylist[index].upStatus = 0
          this.data.activitylist[index].upNum -= 1
          // console.log(945)
          // console.log(this.data.activitylist[index])
          this.setData({
            activitylist: this.data.activitylist
          })
        }

      }
      // this.setData({
      //   'detail.content.upStatus': false,
      //   'detail.content.upNum': this.data.detail.content.upNum -= 1
      // })
    })
  },
  //加上赞
  upNews(id, index) {
    wx.teamApi.news.upNews(id).then(res => {
      if (res.data.errcode === 0) {
        if (this.data.adminActTab === 'adminNewsTab') {
          console.log(960)
          this.data.newslist[index].upStatus = 1
          this.data.newslist[index].upNum += 1
          //console.log(this.data.infoList[index])
          this.setData({
            newslist: this.data.newslist
          })
        } else {
          console.log('960')
          this.data.activitylist[index].upStatus = 1
          this.data.activitylist[index].upNum += 1
          this.setData({
            activitylist: this.data.activitylist
          })
        }

      }
      // this.setData({
      //   'detail.content.upStatus': true,
      //   'detail.content.upNum': this.data.detail.content.upNum += 1
      // })
    })
  },
})